"use strict";

const commonService = requireService("common");
const url = require("url");

/**
 * api 默认版本
 * @type {String}
 */
const DEF_VERSION = (
            (
                getSysConfig("apiConf") || {}
            )["/ai/material"] || {}
        ).version || "1.0.0";

/**
 * 获取物料外部通用接口
 */
function onGet(ctx) {
    var version = ctx.query.v || DEF_VERSION;
    commonService.setHeader.call(ctx);
    ctx.body = commonService.buildScriptLoader(
        url.format({
            "host": ctx.header.host
            ,"protocol": "http"
            ,"pathname": `/api/ai/${version}/material/${ctx.params.id}`
            ,"query": ctx.query
        })
    );
}

module.exports = {
    "/ai/material/:id":["GET", onGet]
}
